home *** CD-ROM | disk | FTP | other *** search
/ MacAddict 104 / MacAddict_104_2005-04.iso / Software / Internet & Communication / WordPress 1.2.2 freeware.dmg / wordpress / wp-login.php < prev    next >
Encoding:
PHP Script  |  2004-12-16  |  7.6 KB  |  232 lines

  1. <?php
  2. require('./wp-config.php');
  3.  
  4. if (!function_exists('add_magic_quotes')) {
  5.     function add_magic_quotes($array) {
  6.         foreach ($array as $k => $v) {
  7.             if (is_array($v)) {
  8.                 $array[$k] = add_magic_quotes($v);
  9.             } else {
  10.                 $array[$k] = addslashes($v);
  11.             }
  12.         }
  13.         return $array;
  14.     } 
  15. }
  16.  
  17. if (!get_magic_quotes_gpc()) {
  18.     $_GET    = add_magic_quotes($_GET);
  19.     $_POST   = add_magic_quotes($_POST);
  20.     $_COOKIE = add_magic_quotes($_COOKIE);
  21. }
  22.  
  23. $wpvarstoreset = array('action');
  24.  
  25. for ($i = 0; $i < count($wpvarstoreset); $i = $i + 1) {
  26.     $wpvar = $wpvarstoreset[$i];
  27.     if (!isset($$wpvar)) {
  28.         if (empty($_POST["$wpvar"])) {
  29.             if (empty($_GET["$wpvar"])) {
  30.                 $$wpvar = '';
  31.             } else {
  32.                 $$wpvar = $_GET["$wpvar"];
  33.             }
  34.         } else {
  35.             $$wpvar = $_POST["$wpvar"];
  36.         }
  37.     }
  38. }
  39.  
  40. $error = '';
  41.  
  42. header('Expires: Wed, 11 Jan 1984 05:00:00 GMT');
  43. header('Last-Modified: ' . gmdate('D, d M Y H:i:s') . ' GMT');
  44. header('Cache-Control: no-cache, must-revalidate');
  45. header('Pragma: no-cache');
  46.  
  47. switch($action) {
  48.  
  49. case 'logout':
  50.  
  51.     setcookie('wordpressuser_' . COOKIEHASH, ' ', time() - 31536000, COOKIEPATH);
  52.     setcookie('wordpresspass_' . COOKIEHASH, ' ', time() - 31536000, COOKIEPATH);
  53.  
  54.     if ($is_IIS)
  55.         header('Refresh: 0;url=wp-login.php');
  56.     else
  57.         header('Location: wp-login.php');
  58.     exit();
  59.  
  60. break;
  61.  
  62. case 'lostpassword':
  63.  
  64.     ?>
  65. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  66. <html xmlns="http://www.w3.org/1999/xhtml">
  67. <head>
  68.     <title>WordPress » <?php _e('Lost Password') ?></title>
  69.     <meta http-equiv="Content-Type" content="text/html; charset=<?php bloginfo('charset'); ?>" />
  70.     <link rel="stylesheet" href="wp-admin/wp-admin.css" type="text/css" />
  71.     <script type="text/javascript">
  72.     function focusit() {
  73.         // focus on first input field
  74.         document.getElementById('user_login').focus();
  75.     }
  76.     window.onload = focusit;
  77.     </script>
  78. </head>
  79. <body>
  80. <div id="login">
  81. <h1><a href="http://wordpress.org/">WordPress</a></h1>
  82. <p><?php _e('Please enter your information here. We will send you a new password.') ?></p>
  83. <?php
  84. if ($error)
  85.     echo "<div id='login_error'>$error</div>";
  86. ?>
  87.  
  88. <form name="lostpass" action="wp-login.php" method="post" id="lostpass">
  89. <p>
  90. <input type="hidden" name="action" value="retrievepassword" />
  91. <label><?php _e('Login') ?>: <input type="text" name="user_login" id="user_login" value="" size="12" tabindex="1" /></label><br />
  92. <label><?php _e('E-mail') ?>: <input type="text" name="email" id="email" value="" size="12" tabindex="2" /></label><br />
  93. </p>
  94. <p class="submit"><input type="submit" name="submit" value="<?php _e('Retrieve Password'); ?> »" tabindex="3" /></p>
  95. </form>
  96. </div>
  97. </body>
  98. </html>
  99. <?php
  100. break;
  101.  
  102. case 'retrievepassword':
  103.  
  104.     $user_data = get_userdatabylogin($_POST['user_login']);
  105.     // redefining user_login ensures we return the right case in the email
  106.     $user_login = $user_data->user_login;
  107.     $user_email = $user_data->user_email;
  108.  
  109.     if (!$user_email || $user_email != $_POST['email'])
  110.         die(sprintf(__('Sorry, that user does not seem to exist in our database. Perhaps you have the wrong username or e-mail address? <a href="%s">Try again</a>.'), 'wp-login.php?action=lostpassword'));
  111.  
  112.     // Generate something random for a password... md5'ing current time with a rand salt
  113.     $user_pass = substr( MD5('time' . rand(1, 16000) ), 0, 6);
  114.     // now insert the new pass md5'd into the db
  115.      $wpdb->query("UPDATE $wpdb->users SET user_pass = MD5('$user_pass') WHERE user_login = '$user_login'");
  116.     $message  = __('Login') . ": $user_login\r\n";
  117.     $message .= __('Password') . ": $user_pass\r\n";
  118.     $message .= get_settings('siteurl') . '/wp-login.php';
  119.  
  120.     $m = wp_mail($user_email, sprintf(__("[%s] Your login and password"), get_settings('blogname')), $message);
  121.  
  122.     if ($m == false) {
  123.          echo '<p>' . __('The e-mail could not be sent.') . "<br />\n";
  124.          echo  __('Possible reason: your host may have disabled the mail() function...') . "</p>";
  125.         die();
  126.     } else {
  127.         echo '<p>' .  sprintf(__("The e-mail was sent successfully to %s's e-mail address."), $user_login) . '<br />';
  128.         echo  "<a href='wp-login.php' title='" . __('Check your e-mail first, of course') . "'>" . __('Click here to login!') . '</a></p>';
  129.         // send a copy of password change notification to the admin
  130.         wp_mail(get_settings('admin_email'), sprintf(__('[%s] Password Lost/Change'), get_settings('blogname')), sprintf(__('Password Lost and Changed for user: %s'), $user_login));
  131.         die();
  132.     }
  133.  
  134. break;
  135.  
  136. case 'login' : 
  137. default:
  138.  
  139.     $user_login = '';
  140.     $user_pass = '';
  141.     $redirect_to = '';
  142.     $using_cookie = false;
  143.  
  144.     if( !empty($_POST) ) {
  145.         $user_login = $_POST['log'];
  146.         $user_pass = $_POST['pwd'];
  147.         $redirect_to = preg_replace('|[^a-z0-9-~+_.?#=&;,/:]|i', '', $_POST['redirect_to']);
  148.     } elseif ( !empty($_COOKIE) ) {
  149.         if (! empty($_COOKIE['wordpressuser_' . COOKIEHASH]))
  150.             $user_login = $_COOKIE['wordpressuser_' . COOKIEHASH];
  151.         if (! empty($_COOKIE['wordpresspass_' . COOKIEHASH])) {
  152.             $user_pass = $_COOKIE['wordpresspass_' . COOKIEHASH];
  153.             $using_cookie = true;
  154.         }
  155.         $redirect_to = 'wp-admin/';
  156.     }
  157.     
  158.     $user = get_userdatabylogin($user_login);
  159.     if (0 == $user->user_level) {
  160.         $redirect_to = get_settings('siteurl') . '/wp-admin/profile.php';
  161.     }
  162.  
  163.     if ($user_login && $user_pass) {
  164.         if ( wp_login($user_login, $user_pass, $using_cookie) ) {
  165.             if (! $using_cookie) {
  166.                 $user_pass = md5(md5($user_pass)); // Double hash the password in the cookie.
  167.                 setcookie('wordpressuser_'. COOKIEHASH, $user_login, time() + 31536000, COOKIEPATH);
  168.                 setcookie('wordpresspass_'. COOKIEHASH, $user_pass, time() + 31536000, COOKIEPATH);
  169.             }
  170.  
  171.             if ($is_IIS)
  172.                 header("Refresh: 0;url=$redirect_to");
  173.             else
  174.                 header("Location: $redirect_to");
  175.             exit();
  176.         } else {
  177.             if ($using_cookie)            
  178.                 $error = __('Your session has expired.');
  179.         }
  180.     }
  181.     
  182.     ?>
  183. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  184. <html xmlns="http://www.w3.org/1999/xhtml">
  185. <head>
  186.     <title>WordPress › <?php _e('Login') ?></title>
  187.     <meta http-equiv="Content-Type" content="text/html; charset=<?php bloginfo('charset'); ?>" />
  188.     <link rel="stylesheet" href="wp-admin/wp-admin.css" type="text/css" />
  189.     <script type="text/javascript">
  190.     function focusit() {
  191.         // focus on first input field
  192.         document.getElementById('log').focus();
  193.     }
  194.     window.onload = focusit;
  195.     </script>
  196. </head>
  197. <body>
  198.  
  199. <div id="login">
  200. <h1><a href="http://wordpress.org/">WordPress</a></h1>
  201. <?php
  202. if ($error)
  203.     echo "<div id='login_error'>$error</div>";
  204. ?>
  205.  
  206. <form name="loginform" id="loginform" action="wp-login.php" method="post">
  207. <p><label><?php _e('Login') ?>: <input type="text" name="log" id="log" value="" size="20" tabindex="1" /></label></p>
  208. <p><label><?php _e('Password') ?>: <input type="password" name="pwd" value="" size="20" tabindex="2" /></label></p>
  209. <p class="submit"><input type="submit" name="submit" value="<?php _e('Login'); ?> »" tabindex="3" />
  210. <?php if (isset($_GET["redirect_to"])) { ?>
  211.     <input type="hidden" name="redirect_to" value="<?php echo $_GET["redirect_to"] ?>" />
  212. <?php } else { ?>
  213.     <input type="hidden" name="redirect_to" value="wp-admin/" />
  214. <?php } ?>
  215. </p>
  216. </form>
  217. <ul>
  218.     <li><a href="<?php echo get_settings('home'); ?>" title="<?php _e('Are you lost?') ?>">« <?php _e('Back to blog') ?></a></li>
  219. <?php if (get_settings('users_can_register')) : ?>
  220.     <li><a href="<?php echo get_settings('siteurl'); ?>/wp-register.php"><?php _e('Register') ?></a></li>
  221. <?php endif; ?>
  222.     <li><a href="<?php echo get_settings('siteurl'); ?>/wp-login.php?action=lostpassword" title="<?php _e('Password Lost and Found') ?>"><?php _e('Lost your password?') ?></a></li>
  223. </ul>
  224. </div>
  225.  
  226. </body>
  227. </html>
  228. <?php
  229.  
  230. break;
  231. } // end action switch
  232. ?>